package org.adorsys.aderp.jpa.xls;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.adorsys.xlseasy.boot.DateStylesInspector;
import org.adorsys.xlseasy.utils.XlseasyUtils;
import org.springframework.util.ReflectionUtils;

public class AderpJpaDateStylesInspector implements DateStylesInspector {
	private Map<Class<?>, Map<String, String>> fieldDateStylesMap = new HashMap<Class<?>, Map<String, String>>();


	public AderpJpaDateStylesInspector(Class<?> dataKlass){
		List<Field> workbookFields = XlseasyUtils.readWorkbookFields(dataKlass);
		for (Field field : workbookFields) {
			Class<?> elementType = XlseasyUtils.extractElementType(field);
			if(elementType==null) continue;
			// gather date time formaters
			HashMap<String,String> fieldDateStyles = new HashMap<String, String>();
			fieldDateStylesMap.put(elementType, fieldDateStyles);
			ReflectionUtils.doWithFields(elementType, new CollectingDateTimeFieldCallback(fieldDateStyles));
		}
	}
	@Override
	public Map<String, String> inspectDateStyles(Class<?> sheetKlass) {
		return fieldDateStylesMap.get(sheetKlass);
	}

}
